package com.qiaofang.applet.service.member.service.mapstruct;

import com.qiaofang.applet.constants.BusinessConstants;
import com.qiaofang.applet.service.member.domain.MemberOperate;
import com.qiaofang.applet.service.member.service.dto.*;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

import java.util.ArrayList;
import java.util.List;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MemberOperateMapper {

    MemberOperate exploreDtoToDomain(MemberExploreAddDto memberExploreAddDto);

    MemberOperate shareDtoToDomain(MemberShareAddDto memberShareAddDto);

    MemberOperate exchangeDtoToDomain(MemberExchangeAddDto memberExchangeAddDto);

    DailyDataForVisitDto TodayVisitDtoToDailyDataForVisitDto(TodayVisitDto todayVisitDto);

    DailyDataForForwardDto TodayForwardDtoToDailyDataForForwardDto(TodayForwardDto todayForwardDto);

    DailyDataForExchangeDto TodayExchangeDtoToDailyDataForExchangeDto(TodayExchangeDto todayExchangeDto);

    default List<MemberExploreDetailDto> domainToDetailDto(List<MemberOperate> list) {
        if ( list == null ) {
            return null;
        }

        List<MemberExploreDetailDto> list1 = new ArrayList<MemberExploreDetailDto>( list.size() );
        for ( MemberOperate memberOperate : list ) {
            list1.add( memberOperateToMemberExploreDetailDto( memberOperate ) );
        }

        return list1;
    }

    default MemberExploreDetailDto memberOperateToMemberExploreDetailDto(MemberOperate memberOperate) {
        if ( memberOperate == null ) {
            return null;
        }

        MemberExploreDetailDto memberExploreDetailDto = new MemberExploreDetailDto();

        memberExploreDetailDto.setId( memberOperate.getId() );
        memberExploreDetailDto.setMemberId( memberOperate.getMemberId() );
        memberExploreDetailDto.setMemberName( memberOperate.getMemberName() );
        memberExploreDetailDto.setCreateTime( memberOperate.getCreateTime() );
        memberExploreDetailDto.setCityName( memberOperate.getCityName() );
        memberExploreDetailDto.setBusinessUuid( memberOperate.getBusinessUuid() );
        if ( memberOperate.getBusinessType() != null ) {

            switch (memberOperate.getBusinessType()){
                case 1:memberExploreDetailDto.setBusinessType(BusinessConstants.FIRSTHAND_ESTATE.getValue());break;
                case 2:memberExploreDetailDto.setBusinessType(BusinessConstants.SALE_PROPERTY.getValue());break;
                case 3:memberExploreDetailDto.setBusinessType(BusinessConstants.RENT_PROPERTY.getValue());break;
                case 4:memberExploreDetailDto.setBusinessType(BusinessConstants.EMPLOYEE.getValue());break;
            }
        }
        memberExploreDetailDto.setEstateName( memberOperate.getEstateName() );
        memberExploreDetailDto.setHouseType( memberOperate.getHouseType() );
        memberExploreDetailDto.setPrice( memberOperate.getPrice() );
        memberExploreDetailDto.setPropertyNo( memberOperate.getPropertyNo() );

        return memberExploreDetailDto;
    }

    default MemberShareTracksDto domainToShareTracksDto(MemberOperate memberOperate){
        if ( memberOperate == null ) {
            return null;
        }

        MemberShareTracksDto memberShareTracksDto = new MemberShareTracksDto();

        memberShareTracksDto.setId( memberOperate.getId());
        memberShareTracksDto.setMemberName( memberOperate.getMemberName() );
        memberShareTracksDto.setMemberId( memberOperate.getMemberId() );
        if ( memberOperate.getBusinessType() != null ) {
            memberShareTracksDto.setBusinessType(BusinessConstants.EMPLOYEE.getCode().equals(memberOperate.getBusinessType()) ? "名片" : "房源");
        }
        memberShareTracksDto.setLevel( memberOperate.getLevel() );
        memberShareTracksDto.setLinkedUuid( memberOperate.getLinkedUuid() );
        memberShareTracksDto.setParentId( memberOperate.getParentId() );

        return memberShareTracksDto;
    }

    default MemberShareGetDto domainToShareGetDto(MemberOperate memberOperate) {
        if (memberOperate == null) {
            return null;
        }

        MemberShareGetDto memberShareGetDto = new MemberShareGetDto();

        memberShareGetDto.setShowEmpList(memberOperate.getShowEmpList());
        memberShareGetDto.setBusinessUuid(memberOperate.getBusinessUuid());
        memberShareGetDto.setBusinessType(memberOperate.getBusinessType());
        memberShareGetDto.setEmployeeUniqueUuid(memberOperate.getEmployeeUniqueUuid());
        memberShareGetDto.setCityCode(memberOperate.getCityCode());

        return memberShareGetDto;
    }

}
